home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 196_01 / fp_test.c < prev    next >
Text File  |  1985-11-13  |  4KB  |  193 lines

  1. /* [FP-TEST.C of JUGPDS Vol.19]
  2. *****************************************************************
  3. *                                *
  4. *    Written by  Hakuo Katayose (JUG-CP/M No.179)        *
  5. *            49-114 Kawauchi-Sanjuunin-machi        *
  6. *                Sendai, Miyagi 980                          *
  7. *            Phone: 0222-61-3219                *
  8. *                                *
  9. *    Edited & tested by Y. Monma (JUG-C/M Disk Editor)       * 
  10. *                                *
  11. *****************************************************************
  12. */
  13.  
  14. /* Test Program for fp64(Func_No,a,b,c); */
  15.  
  16. #include <bdscio.h>
  17. #include <dio.h>
  18.  
  19. #define    FPGETK    0  /* get constant internally defined in fp64 */
  20. #define    FPADD    1    /* addition:       c = a + b    */
  21. #define    FPSUB    2    /* subtraction:    c = a - b    */
  22. #define    FPMUL    3    /* multiplication: c = a * b     */ 
  23. #define    FPDIV    4    /* division:       c = a / b    */
  24. #define    FPCMP    5    /* comparison:     c = 1 if a > b,
  25.                            c = 0 if a = b,
  26.                            c = -1 if a < b    */
  27. #define    FPNEG    6    /* negation:       c = - a    */
  28. #define    FPSFT    7    /* shift:       c = a * 2**2 */ 
  29. #define    FPHLF    8    /* half:        c = a / 2     */
  30. #define    FPDBL    9    /* double:       c = b * 2    */
  31.  
  32. #define    FPCNV    10    /* format conversion for output */
  33. #define    FPIN    11    /* format conversion for input  */
  34.  
  35. #define    FPSQRT    12    /* square root:   c = sqrt(a)    */
  36. #define    SINCOS    13    /* b = cos(a), c = ain(a), a is in radian */
  37. #define    ATAN2    14    /* c = arctan(a/b)    */
  38. #define    EXP    15    /* c = 2**b    */    
  39. #define    LOG    16    /* c = log[2]b  */
  40.  
  41. #define    LLADD    21
  42. #define    LLSUB    22
  43. #define    LLMUL    23
  44. #define    LLDIV    24
  45.  
  46. #define    LLCMP    25
  47. #define    LLNEG    26
  48. #define    LLMOV    27
  49. #define    LLSFTL    28
  50. #define    LLSFTR    29
  51. #define    ATOLL    30
  52. #define    LLTOA    31
  53. #define    LLTEN    32
  54.  
  55.  
  56. #define    FPTST1    255
  57. #define    FPTST2    254
  58.  
  59. main(argc, argv)
  60. char **argv;
  61. {
  62.     char    a[8], b[8], c[8], t[8], z[8];
  63.     char    s[40], one[8];
  64.     int    i;
  65.  
  66. /*
  67.     dioinit(&argc, argv);
  68. */
  69.     puts("** Test of fp64(Func_No,a,b,c); **\n");
  70.     putchar('\n');
  71.     test_exp();
  72.     test_log();
  73.     test_sincos();
  74.     test_atan2();
  75.     test_sqrt();
  76. /*    test_            ; additinal test module 
  77.     dioflush();
  78. */
  79. }
  80.  
  81.  
  82. test_exp()
  83. {
  84.     char    a[8], b[8];
  85.     char    s[40];
  86.     int    i;
  87.  
  88.     for (;;) {
  89.         puts("Input data A for fp64(EXP,A,0,C);\n");
  90.         puts("Simple <CR> proceeds next function.\n");
  91.         gets(s);
  92.         if (strlen(s) <= 0)
  93.             break;
  94.         fp64(FPIN, s, 0, a);
  95.         fp64(EXP, a, 0, b);
  96.         elist(a);    elist(b);    putchar('\n');
  97.     }
  98. }
  99.  
  100.  
  101. test_log()
  102. {
  103.     char    a[8], b[8];
  104.     char    s[40];
  105.     int    i;
  106.  
  107.     for (;;) {
  108.         puts("Input data A for fp64(LOG,A,0,C): ");
  109.         gets(s);
  110.         if (strlen(s) <= 0)
  111.             break;
  112.         fp64(FPIN, s, 0, a);
  113.         fp64(LOG, a, 0, b);
  114.         elist(a);    elist(b);    putchar('\n');
  115.     }
  116. }
  117.  
  118.  
  119. test_sincos()
  120. {
  121.     char    a[8],b[8],c[8],z[8];
  122.     int    i;
  123.  
  124.     puts("*******  sin  cos  *****\n");
  125.     fp64(FPIN, "2", 0, a);
  126.     fp64(FPIN, "2", 0, z);
  127.     for (i = 0; i <= 18; i++) {
  128.         fp64(SINCOS, a, b, c);
  129.         elist(a);    elist(b);    elist(c);
  130.         putchar('\n');
  131.         fp64(FPDIV, a, z, a);
  132.     }
  133. }
  134.  
  135.  
  136. test_atan2()
  137. {
  138.     char    a[8], b[8], c[8], z[8];
  139.     int    i;
  140.  
  141.     puts("*****  atan  *****\n");
  142.     fp64(FPIN, "2", 0, b);
  143.     fp64(FPIN, "0.1", 0, a);
  144.     fp64(FPIN, "0.1", 0, z);
  145.     for (i = 0; i < 10; i++) {
  146.         fp64(ATAN2, a, b, c);
  147.         elist(c);    elist(a);    elist(b);    putchar('\n');
  148.         fp64(FPADD, a, z, a);
  149.         }
  150.     elist(c);
  151.     putchar('\n');    putchar('\n');
  152. }
  153.  
  154. test_sqrt()
  155. {
  156.     char    a[8], b[8];
  157.     char    s[40];
  158.  
  159.     for (; ; ) {
  160.         puts("Input data A for fp64(FPSQRT,A,0,C): ");
  161.         gets(s);
  162.         if (strlen(s) <= 0)
  163.             break;
  164.         fp64(FPIN, s, 0, a);
  165.         elist(a);    putchar('\n');
  166.         fp64(FPSQRT, a, 0, b);    elist(b);    putchar('\n');
  167.     }
  168.  
  169. }
  170.  
  171.  
  172. flist(s)
  173. char *s;
  174. {
  175.     char    *p;
  176.     int    ep, i;
  177.  
  178.     for(i = 0; i < 8; i++) printf("%02x|",*s++);
  179.     puts("   ");
  180. }
  181.  
  182.  
  183. elist(s)
  184. char *s;
  185. {
  186.     char    *p;
  187.     int    ep, i;
  188.  
  189.     p = fp64(FPCNV, s);
  190.     ep = *p++ + *p++ * 256;
  191.     printf("%15sE%4d   ", p, ep);
  192. }
  193.